home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / gnu / ixpath.lha / ixpath / macro.h < prev    next >
C/C++ Source or Header  |  1995-12-19  |  4KB  |  94 lines

  1. #ifndef MACRO_H
  2. #define MACRO_H
  3.  
  4.  
  5. #define PATCH_INIT(osfun, ixfun, failrc)                      \
  6.                                                               \
  7.   static void (*osfun)(void) = NULL;                          \
  8.                                                               \
  9.   static void                                                 \
  10.   ixfun(void)                                                 \
  11.   {                                                           \
  12.     asm volatile(                                             \
  13.       "movem.l  d6/d7,-(sp)        ;"                         \
  14.       "move.l   #" #failrc ",d7    ;");
  15.  
  16.  
  17. #define PATCH_EXIT                                            \
  18.                                                               \
  19.     asm volatile(                                             \
  20.       "move.l   d7,d0              ;"                         \
  21.       "movem.l  (sp)+,d6/d7        ;");                       \
  22.   }
  23.  
  24.  
  25. #define PATCH_LAB(ixfun, reg)                                 \
  26.                                                               \
  27.     asm volatile (#ixfun #reg ":");
  28.  
  29.  
  30. #define PATCH_PUSH(ixfun, reg)                                \
  31.                                                               \
  32.     asm volatile(                                             \
  33.       "move.l   d7,-(sp)           ;"                         \
  34.       "movem.l  d0/d1/a0/a1,-(sp)  ;"                         \
  35.       "move.l   " #reg ",-(sp)     ;"                         \
  36.       "bsr      _make_ospath       ;"                         \
  37.       "addq.l   #4,sp              ;"                         \
  38.       "move.l   d0,d7              ;"                         \
  39.       "movem.l  (sp)+,d0/d1/a0/a1  ;"                         \
  40.       "move.l   d7," #reg "        ;"                         \
  41.       "move.l   (sp)+,d7           ;"                         \
  42.       "tst.l    " #reg "           ;"                         \
  43.       "beq      " #ixfun #reg "    ;"                         \
  44.       "move.l   " #reg ",-(sp)     ;");
  45.  
  46.  
  47. #define PATCH_POP                                             \
  48.                                                               \
  49.     asm volatile(                                             \
  50.       "bsr      _IoErr             ;"                         \
  51.       "move.l   d0,d6              ;"                         \
  52.       "bsr      _FreeVec           ;"                         \
  53.       "addq.l   #4,sp              ;"                         \
  54.       "move.l   d6,-(sp)           ;"                         \
  55.       "bsr      _SetIoErr          ;"                         \
  56.       "addq.l   #4,sp              ;");
  57.  
  58.  
  59. #define PATCH_CALL(osfun)                                     \
  60.                                                               \
  61.     asm volatile(                                             \
  62.       "move.l   a5,-(sp)           ;"                         \
  63.       "move.l   _" #osfun ",a5     ;"                         \
  64.       "jsr      (a5)               ;"                         \
  65.       "move.l   d0,d7              ;"                         \
  66.       "move.l   (sp)+,a5           ;");
  67.  
  68.  
  69. #define DEF_PATCH1(osfun, ixfun, failrc, reg)                 \
  70.                                                               \
  71.   PATCH_INIT(osfun, ixfun, failrc)                            \
  72.     PATCH_PUSH(ixfun, reg)                                    \
  73.       PATCH_CALL(osfun)                                       \
  74.       PATCH_POP                                               \
  75.     PATCH_LAB(ixfun, reg)                                     \
  76.   PATCH_EXIT
  77.  
  78.  
  79. #define DEF_PATCH2(osfun, ixfun, failrc, reg1, reg2)          \
  80.                                                               \
  81.   PATCH_INIT(osfun, ixfun, failrc)                            \
  82.     PATCH_PUSH(ixfun, reg1)                                   \
  83.       PATCH_PUSH(ixfun, reg2)                                 \
  84.         PATCH_CALL(osfun)                                     \
  85.         PATCH_POP                                             \
  86.       PATCH_LAB(ixfun, reg2)                                  \
  87.       PATCH_POP                                               \
  88.     PATCH_LAB(ixfun, reg1)                                    \
  89.   PATCH_EXIT
  90.  
  91.  
  92. #endif
  93.  
  94.